package com.ruoyi.electricity.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.electricity.domain.ElectricParameter;
import com.ruoyi.electricity.service.ElectricParameterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用电设备Controller
 *
 * @author ljw
 * @date 2023-08-29*/


@RestController
@RequestMapping("/electricity/electricParameter")
public class ElectricParameterController extends BaseController
{
    @Autowired
    private ElectricParameterService electricParameterService;

    @GetMapping("/list")
    public TableDataInfo list(ElectricParameter electricParameter)
    {
        startPage();
        List<ElectricParameter> list = electricParameterService.selectElectricParameterList(electricParameter);
        return getDataTable(list);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, ElectricParameter electricParameter)
    {
        List<ElectricParameter> list = electricParameterService.selectElectricParameterList(electricParameter);
        ExcelUtil<ElectricParameter> util = new ExcelUtil<ElectricParameter>(ElectricParameter.class);
        util.exportExcel(response, list, "用电设备数据");
    }

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(electricParameterService.selectElectricParameterById(id));
    }

    @PostMapping
    public AjaxResult add(@RequestBody ElectricParameter electricParameter)
    {
        return toAjax(electricParameterService.insertElectricParameter(electricParameter));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody ElectricParameter electricParameter)
    {
        return toAjax(electricParameterService.updateElectricParameter(electricParameter));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(electricParameterService.deleteElectricParameterByIds(ids));
    }
}

